//
//  AY_BookUpdateCell.m
//  AiYue
//
//  Created by boWen on 2023/10/24.
//

#import "AY_BookUpdateCell.h"


@interface AY_BookUpdateCell ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UILabel * leftLabel;
@property (nonatomic, strong) UILabel * rightLabel;
@property (nonatomic, strong) UIImageView * arrowImgView;
@property (nonatomic, strong) UIImageView * avatarImgView;
@property (nonatomic, strong) NSArray * dataLeftAry;
@property (nonatomic, strong) NSArray * dataLeftSubAry;

@end

@implementation AY_BookUpdateCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}

- (void)addAllSubviewsWithUI {
    self.dataLeftAry = @[@"头像", @"昵称", @"ID", @"性别"];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(0) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.leftLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(16) weight:UIFontWeightRegular] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View);
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.height.mas_equalTo(YNUM(22));
    }];
    
    self.arrowImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_my_arrowNight.png") andBg:[UIColor whiteColor] andRadius:0.0 andAddSubView:self.bg_View];
    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(16));
        make.width.mas_equalTo(YNUM(16));
        make.right.equalTo(self.bg_View).offset(YNUM(-14));
        make.centerY.equalTo(self.bg_View);
    }];
    
    self.avatarImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_my_tx.png") andBg:[UIColor whiteColor] andRadius:22.5 andAddSubView:self.bg_View];
    [self.avatarImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(45));
        make.width.mas_equalTo(YNUM(45));
        make.right.equalTo(self.arrowImgView.mas_left).offset(YNUM(-5));
        make.centerY.equalTo(self.bg_View);
    }];
    
    self.rightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View);
        make.right.equalTo(self.arrowImgView.mas_left).offset(YNUM(-4));
        make.height.mas_equalTo(YNUM(22));
    }];
}

- (void)setData:(NSIndexPath *)index userInfo:(UserInfo *)userInfo {
      self.leftLabel.text = self.dataLeftAry[index.row];
        if(index.row == 0) {
            self.avatarImgView.hidden = NO;
            [self.avatarImgView sd_setImageWithURL:[NSURL URLWithString:userInfo.avatar] placeholderImage:YImage(@"icon_my_tx")];
            self.rightLabel.hidden = YES;
        }else {
            self.rightLabel.hidden = NO;
            self.avatarImgView.hidden = YES;
        }
        if (index.row == 2) {
            self.arrowImgView.hidden = YES;
        }else {
            self.arrowImgView.hidden = NO;
        }
        switch (index.row) {
            case 1:
                self.rightLabel.text = userInfo.nickName;
                break;
            case 2:
                self.rightLabel.text = userInfo.userName;
                break;
            case 3:
                self.rightLabel.text = [userInfo.gender isEqualToString:@"1"] ? @"男" : [userInfo.gender isEqualToString:@"2"]? @"女":@"";
                break;
            default:
                break;
        }
}

@end
